<script lang="ts" setup>
import { reactive, ref } from "vue";
import type { FormInstance } from "element-plus";
import { ElMessage } from "element-plus";
// import { useCounter } from "@/stores/counter";
import { useRouter } from "vue-router";
import { goLogin, goTest } from "@/api/login";

const router = useRouter();
// const Counter = useCounter();
const ruleFormRef = ref<FormInstance>();
const ruleForm = reactive({
  username: "",
  password: "",
});
const rules = reactive({
  username: [{ required: true, message: "请输入用户名", trigger: "blur" }],
  password: [{ required: true, message: "请输入密码", trigger: "blur" }],
});
const submitForm = async (formEl: FormInstance | undefined) => {
  
  console.log('123');
  
  if (!formEl) return;
  sessionStorage.setItem("token", '12345');
     router.push("/home");
  // await formEl.validate((valid, fields) => {
  //   if (valid) {
  //     // const params = {
  //     //   username: ruleForm.username,
  //     //   password: ruleForm.password,
  //     // };
  //     // goLogin(params).then((e: any) => {
  //     //   if (e.code === 200) {
  //     //     ElMessage({
  //     //       message: e.msg || "登录成功",
  //     //       type: "success",
  //     //     });
  //     //     // Counter.setToken(e.token); //存入token
  //     //     sessionStorage.setItem("token", e.token);
  //     //     router.push("/home");
  //     //   } else {
  //     //     ElMessage.error(e.msg || "账号或密码错误");
  //     //   }
  //     // });
  //     //  router.push("/home");
  //   }
  // });
};
const reset = () => {
  // ruleForm.username = "";
  // ruleForm.password = "";
  // goTest().then((e: any) => {
  //   console.log("测试的调取接口", e);
  // });
};
</script>
<template>
  <div class="login">
    <div class="login-box">
      <div class="login-left">
        <img src="@/assets/img/ic_login_left.png" alt="" />
      </div>
      <div class="login-right">
        <div class="form-head animate__animated animate__lightSpeedInRight">
          <!-- <img src="@/assets/img/ic_logo.png" alt="" /> -->
          Eff-Admin
        </div>
        <div class="form-content"></div>
        <el-form
          ref="ruleFormRef"
          style="max-width: 600px"
          :model="ruleForm"
          status-icon
          :rules="rules"
          label-width="auto"
          class="demo-ruleForm"
        >
          <el-form-item label="账号" prop="username">
            <el-input
              v-model="ruleForm.username"
              autocomplete="off"
              placeholder="admin"
            />
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input
              v-model="ruleForm.password"
              type="password"
              autocomplete="off"
              placeholder="admin"
            />
          </el-form-item>
          <el-form-item>
            <div class="btn">
              <el-button >重置</el-button>
              <el-button type="success" @click="submitForm(ruleFormRef)"
                >登录</el-button
              >
            </div>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div class="record">蜀ICP备2024097599号</div>
  </div>
</template>



<style lang="scss" scoped>
@import url("./index.scss");
</style>